package middleware

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

// AuthMiddleware 验证 access-key
func AuthMiddleware() gin.HandlerFunc {
	return func(c *gin.Context) {
		accessKey := c.GetHeader("access-key")
		if accessKey == "" {
			c.JSON(http.StatusOK, gin.H{
				"errCode": 400,
				"errMsg":  "缺少秘钥参数，请在请求头中添加 access-key",
				"data":    nil,
			})
			c.Abort()
			return
		}

		// 这里可以添加更复杂的验证逻辑
		// 例如验证 access-key 是否有效、是否过期等
		// 目前仅验证是否存在

		c.Set("access_key", accessKey)
		c.Next()
	}
}

